package cn.doit.scala.day03

import scala.io.Source

/**
 * @DATE 2021/12/27/16:38
 * @Author MDK
 * @Version 2021.2.2
 * */
object C12_MapValues {
  def main(args: Array[String]): Unit = {
    val lines: Iterator[String] = Source.fromFile("d://aaa//1.txt").getLines()
    val words: Iterator[String] = lines.flatMap(_.split("\\s+"))
    val tuples: Iterator[(String, String)] = words.map(e => (e, e))


    //将集合转换成map集合   注意是否改变数据结果  Map集合中的Key不能重复
    val mp: Map[String, String] = tuples.toMap
    val res: Map[String, String] = mp.mapValues(_.toUpperCase)
    res.foreach(println)

//    tuples.foreach(println)
    /* // 分组
    val mp: Map[String, List[String]] = words.toList.groupBy(e => e)
     // 没有处理key
    //mp.map(tp=>(tp._1 , tp._2.length))
    val res: Map[String, Int] = mp.mapValues(_.length)
    res.foreach(println)*/

  }
}
